//Extension for fixing some small glitches with the texts at GPS-Speedsurf.
//By Carl Ribbegårdh
//http://www.gps-speedsurfing.com/default.aspx?mnu=user&smnu=sessions&uid=3165

console.log("GPS-Textfix-Extension");

//---------------------------------------------------------------
//-- Change the "$0" to <br/> at the session information pages --
//---------------------------------------------------------------

//If the page is a user page.
var urlIdx = document.URL.indexOf("mnu=user&")
if (-1 != urlIdx) {

    var sessionBox = $("#Master1_ContentPlaceHolder1_ctl00_divSession");
    sessionBox.html(sessionBox.html().replace(/\$0/gi, "<br/>"));
}

//---------------------------------------------------------------
//-- Shorten the url's that break all the layout at the forum  --
//---------------------------------------------------------------

var maxLinkLength = 70;

//If the page is a forum page.
var urlIdx = document.URL.indexOf("mnu=forum&")
if (-1 != urlIdx) {

    //If it's not the front page
    if (-1 != document.URL.indexOf("&val=")) {

        $("#Master1_ContentPlaceHolder1_ctl00_divForumindex")
            .find("td a").each(function(index) {
                //console.log($(this).text());
                var text = $(this).text();
                //If the link text is longer than our chosen max...
                if (maxLinkLength < text.length) {
                    //set a tooltip with the original text.
                    $(this).attr("title", text);
                    //...shorten it to the max length.
                    text = text.substr(0, maxLinkLength) + "...";
                    //and assign it.
                    $(this).text(text);
                }

                $(this).css("text-decoration", "underline");
            });
    }
}
